package com.itheima.web.controller;

import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.QuestionAndOptionsVo;
import com.itheima.domain.vo.SoulReportVo;
import com.itheima.web.manager.SoulTestManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.ParametersAreNonnullByDefault;
import java.io.IOException;
import java.util.Map;

@RestController
public class SoulTestController {

    @Autowired
    private SoulTestManager soulTestManager;

    //分页查询所有测试题
    @GetMapping("/test")
    public PageBeanVo findTest(
           Integer page,Integer limit,String startDate ,String endDate,String category
    ) {
        return soulTestManager.findTest(page,limit,startDate,endDate,category);
    }

    //修改回显
    @GetMapping("/test/{id}")
    public QuestionAndOptionsVo findQuestionAndOptions(@PathVariable Long id) {
        return soulTestManager.findQuestionAndOptions(id);
    }

    //删除题目
    @DeleteMapping("/test/{id}")
    public Map deleteQuestionById(@PathVariable Long id) {
        return soulTestManager.deleteQuestionById(id);
    }

    //修改题目
    @PostMapping("/test/edit")
    public Map updateQuestion(@RequestBody Map<String, String> map) {
        return soulTestManager.updateQuestion(map);
    }

    //新增题目
    @PostMapping("/test/add")
    public Map addQuestionAndOptions(@RequestBody Map<String, String> map) {
        return soulTestManager.addQuestionAndOptions(map);
    }

    //分页查询所有测试题
    @GetMapping("/test/report")
    public PageBeanVo findTestReport(Integer page, Integer limit
    ) {
        return soulTestManager.findTestReport(page,limit);
    }



    @PostMapping("/test/report/test")
    public Map updateReport(@RequestBody SoulReportVo soulReportVo, MultipartFile multipartFile) throws IOException {
        return soulTestManager.updateReport(soulReportVo, multipartFile);
    }


}
